package com.zhang.server.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhang.server.controller.request.CategoryPageRequest;
import com.zhang.server.entity.Category;
import com.zhang.server.mapper.CategoryMapper;
import com.zhang.server.service.ICategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService implements ICategoryService {

    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public List<Category> list() {
        return categoryMapper.list();
    }

    @Override
    public Object page(CategoryPageRequest categoryPageRequest) {
        // 将pageNum、pageSize作为参数传进方法
        PageHelper.startPage(categoryPageRequest.getPageNum(), categoryPageRequest.getPageSize());
        List<Category> adminList = categoryMapper.listByCondition(categoryPageRequest);

        // 将查询结果放到这里,返回，就会自动分页
        return new PageInfo<>(adminList);
    }

    @Override
    public void save(Category category) {
        categoryMapper.save(category);
    }

    @Override
    public Category getById(Integer id) {
        return categoryMapper.getById(id);
    }

    @Override
    public void update(Category category) {
        categoryMapper.update(category);
    }

    @Override
    public void delete(Integer id) {
        categoryMapper.delete(id);
    }
}
